home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Oct 90 / MacApp.Tech$ 10⁄26⁄90 / 2246-Validate on mouseDow-Oct90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  7.4 KB  |  215 lines  |  [TEXT/GEOL]

  1. Item    9869936                         25-Oct-90        05:36PDT
  2.  
  3. From:   POWERUP.ENG                     Power Up Software,PRT
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. Sub:    Validate on mouseDown
  8.  
  9. Attn:   MacApp.Tech$
  10. SentBy: James Plamondon
  11. Date   10/24/90
  12. Subject    Validate on mouseDown
  13. From   James Plamondon
  14. To   MacApp.Tech$
  15.  
  16. Subject:   Validate on mouseDown
  17. Gentlepersons,
  18.  
  19. I've modified MacApp so that it validates the current edit text item when
  20. another control is clicked.  If you're interested in this behaviour (MacApp's,
  21. not mine), read on.
  22.  
  23. When the user begins typing in a TEditText view, the TDialogView displays a
  24. TTEView that overlies the TEditText view.  The TTEView handles the editing.
  25.  
  26. When the user shifts her attention away from the text being edited, though,
  27. and instead focuses her attention of some control by clicking on it, the darn
  28. text is still sitting there, unvalidated.  The user may spend the next five
  29. minutes manipulating buttons, popups, lists, etc., before finally dismissing
  30. the dialog — at which point the text is, at last, validated.  By now the user
  31. has completely forgotten what item he has edited, where it was on the dialog,
  32. what he entered that turned out to be invalid, why he wanted to edit it in the
  33. first place, and so on (possibly even what sex she was before the validation,
  34. if his change of assumed gender in mid-paragraph is any indication).
  35.  
  36. I think that this is less than ideal.
  37.  
  38. Consider the type-in popup, described on pages 3 & 4 of Human Interface Note
  39. #9 (October 1990).  It allows the user to enter a value into an edit text
  40. item, or to select a value from an associated popup menu.  If the value
  41. entered in the edit text item does not match a value in the popup, the value
  42. in the edit text item must be added to the popup's menu.
  43.  
  44. Before you can add the edit text item's value to the popup's menu, though,
  45. you've got to validate it.  This can be done by overriding the popup control's
  46. DoMouseCommand() method as follows:
  47.  
  48. {——————————————————————————————————————————————}
  49.  
  50. TMyPopup.DoMouseCommand(VAR theMouse: Point;
  51.                                  VAR info: EventInfo;
  52.                                  VAR hysteresis: Point): TCommand; OVERRIDE;
  53.     VAR
  54.         theDialog:  TDialogView;
  55.  
  56.     BEGIN
  57.     theDialog := TDialogView(GetDialog);
  58.  
  59.     IF (theDialog <> NIL) &
  60.         (theDialog.fCurrentEditText = fEditText) &
  61.         (fEditText.Validate <> kValidValue)       { Validate() adds a menu
  62. entry if needed }
  63.     THEN DoMouseCommand := NIL
  64.     ELSE DoMouseCommand := INHERITED DoMouseCommand(<…>);
  65.     END;  { DoMouseCommand }
  66.  
  67. {——————————————————————————————————————————————}
  68.  
  69. However, this does not solve the problem in general, but rather in this
  70. specific instance only.  I propose a more general solution, which requires
  71. changing MacApp.
  72.  
  73. First, add the following routine to TView:
  74.  
  75. {——————————————————————————————————————————————}
  76.  
  77. FUNCTION TView.ShiftAttentionTo(theView: TView): BOOLEAN;
  78. { Returns TRUE if SELF can shift its attention to the given view.  The default
  79. does
  80.   nothing, and returns TRUE.  It is overridden in TDialogView (qv) to return
  81. TRUE
  82.   if the current edit text item is successfully deselected. }
  83.   BEGIN
  84.   ShiftAttentionTo := TRUE;
  85.   END;  { ShiftAttentionTo }
  86.  
  87. {——————————————————————————————————————————————}
  88.  
  89. Then, modify TView.HandleMouseDown as follows:
  90.  
  91. {——————————————————————————————————————————————}
  92.  
  93. FUNCTION TView.HandleMouseDown(theMouse: VPoint;
  94.                               VAR info: EventInfo;
  95.                               VAR hysteresis: Point;
  96.                               VAR theCommand: TCommand): BOOLEAN;
  97.  
  98.    VAR
  99.        viewThatHandledMouse: TView;
  100.        theQDMouse:         Point;
  101.        {$IFC   qValidateOnMousedown}
  102.        theDialogView:      TView;      { TDialogView is not defined in UMacApp
  103. }
  104.        {$ENDC  qValidateOnMousedown}
  105.  
  106.    FUNCTION TestMouse(theSubView: TView): BOOLEAN;
  107.  
  108.        VAR
  109.            subViewPt:          VPoint;
  110.  
  111.        BEGIN
  112.        subViewPt := theMouse;
  113.        theSubView.SuperToLocal(subViewPt);
  114.        IF theSubView.ContainsMouse(subViewPt) THEN
  115.            TestMouse := theSubView.HandleMouseDown(subViewPt, info,
  116. hysteresis, theCommand)
  117.        ELSE
  118.            TestMouse := FALSE;
  119.        END;
  120.  
  121.    BEGIN
  122.    HandleMouseDown := FALSE;
  123.    theCommand := NIL;
  124.  
  125.    {Assume if we got here then we already know the mouse is in this view}
  126.  
  127.    viewThatHandledMouse := LastSubViewThat(TestMouse);
  128.  
  129.    {$IFC   qValidateOnMousedown}
  130.    IF viewThatHandledMouse <> NIL
  131.    THEN                                {a subview handled it}
  132.        HandleMouseDown := TRUE
  133.    ELSE
  134.        BEGIN                           {see if we can handle it}
  135.        theDialogView := GetDialogView;
  136.  
  137.        IF IsViewEnabled &
  138.           ((theDialogView = NIL) | theDialogView.ShiftAttentionTo(SELF)) &
  139.           Focus
  140.        THEN                            {we CAN handle it!}
  141.            BEGIN
  142.            theQDMouse := ViewToQDPt(theMouse);
  143.            theCommand := DoMouseCommand(theQDMouse, info, hysteresis);
  144.            HandleMouseDown := TRUE;
  145.            END;  { then }
  146.        END;  { else }
  147.    {$ELSEC qValidateOnMousedown}
  148.    IF viewThatHandledMouse <> NIL THEN                 {a subview handled it}
  149.        HandleMouseDown := TRUE
  150.    ELSE IF IsViewEnabled & Focus THEN                  {see if we can handle
  151. it}
  152.        BEGIN
  153.        theQDMouse := ViewToQDPt(theMouse);
  154.        theCommand := DoMouseCommand(theQDMouse, info, hysteresis);
  155.        HandleMouseDown := TRUE;
  156.        END;
  157.    {$ENDC  qValidateOnMousedown}
  158.    END;
  159.  
  160. {——————————————————————————————————————————————}
  161.  
  162. Lastly, override TView.ShiftAttentionTo() (which we just added to TView) in
  163. TDialogView, as follows:
  164.  
  165. {——————————————————————————————————————————————}
  166.  
  167. FUNCTION TDialogView.ShiftAttentionTo(theView: TView): BOOLEAN; OVERRIDE;
  168. { Returns TRUE if the current edit text item is successfully deselected.
  169.   This method is only called from TView.HandleMouseDown(). }
  170.    VAR
  171.        lastCommand:        TCommand;
  172.  
  173.    BEGIN
  174.    ShiftAttentionTo := TRUE;           { default }
  175.  
  176.    IF (fCurrentEditText <> NIL) &      { we're editing }
  177.       (fTEView <> NIL) &
  178.       (theView <> fCurrentEditText) &  { but the mouseDown isn't in the edited
  179. view }
  180.       (theView <> fTEView) &
  181.       Member(theView, TControl)        { and the new view is a control }
  182.    THEN
  183.        BEGIN
  184.        { Commit the last command to prevent undo from applying to the wrong
  185.          edit text, and to ensure that all changes are made before
  186.          validating. }
  187.        lastCommand := fTEView.GetLastCommand;
  188.  
  189.        IF (lastCommand <> NIL) &
  190.           (lastCommand.fView = fTEView)
  191.        THEN
  192.            fTEView.CommitLastCommand;
  193.  
  194.        ShiftAttentionTo := (fCurrentEditText.Validate = kValidValue);
  195.        END;  { then }
  196.    END;  { ShiftAttentionTo }
  197.  
  198. {——————————————————————————————————————————————}
  199.  
  200. These changes ensure that the current edit text item's text is validated
  201. whenever a mouseDown is directed at another control.  I have found that these
  202. changes simplify a number of my dialogs, in which there is interaction between
  203. the value entered in the edit text item and the other controls in the dialog.
  204.  
  205. I hope that these changes do not prove to be unstable, unwarranted, or
  206. misdirected — that's always rather embarassing.  However, if you want to take
  207. this opportunity to embarass me, please don't hesitate to point out any flaws
  208. in, or possible improvements to, the code.  I promise to take it well — and in
  209. any event, I will remain
  210.  
  211. Yours,
  212.  
  213. James Plamondon
  214.  
  215.